package org.jeecg.modules.rooms.controller;


import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.EnumUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.formula.functions.T;
import org.jeecg.common.Enum.ResultCode;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.common.system.vo.DictModel;
import org.jeecg.modules.business.entity.BusOrderFee;
import org.jeecg.modules.business.entity.BusRoomBookingOrders;
import org.jeecg.modules.business.entity.BusRoomsLivingOrder;
import org.jeecg.modules.business.entity.BusTeam;
import org.jeecg.modules.business.enums.FeeSubjectType;
import org.jeecg.modules.business.service.IBusOrderFeeService;
import org.jeecg.modules.business.service.IBusRoomBookingOrdersService;
import org.jeecg.modules.business.service.IBusRoomsLivingOrderService;
import org.jeecg.modules.business.service.IBusTeamService;
import org.jeecg.modules.fw.entity.FwRoomClean;
import org.jeecg.modules.fw.entity.FwRoomLock;
import org.jeecg.modules.fw.entity.FwRoomRepair;
import org.jeecg.modules.fw.service.IFwRoomCleanService;
import org.jeecg.modules.fw.service.IFwRoomLockService;
import org.jeecg.modules.fw.service.IFwRoomRepairService;
import org.jeecg.modules.pos.entity.PosOrderGoodsPayment;
import org.jeecg.modules.rooms.DTO.*;
import org.jeecg.modules.rooms.Enum.CouponEnums;
import org.jeecg.modules.rooms.Enum.RoomStatusEnum;
import org.jeecg.modules.rooms.Vo.CanUseResultVo;
import org.jeecg.modules.rooms.Vo.FloorBuildingRoomVo;
import org.jeecg.modules.rooms.Vo.FloorWithBuildingVo;
import org.jeecg.modules.rooms.entity.CesRoomLayout;
import org.jeecg.modules.rooms.entity.CesRooms;
import org.jeecg.modules.rooms.service.CesRoomBuildingFloorServiceImpl;
import org.jeecg.modules.rooms.service.CesRoomLayoutPriceServiceImpl;
import org.jeecg.modules.rooms.service.CesRoomLayoutServiceImpl;
import org.jeecg.modules.rooms.service.CesRoomsServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.util.*;
import java.util.stream.Collectors;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author fendo
 * @since 2023-03-07
 */
@Api(tags="楼栋")
@Slf4j
@RestController
@RequestMapping("/rooms/cesRooms")
public class CesRoomsController {
    @Resource
    private CesRoomsServiceImpl roomsService;

    @Autowired
    private CesRoomBuildingFloorServiceImpl buildingFloorService;

    @Autowired
    private CesRoomLayoutServiceImpl layoutService;

    @Resource
    private IBusRoomBookingOrdersService bookingOrdersService;

    @Resource
    private IBusTeamService teamService;

    @Resource
   private IBusOrderFeeService busOrderFeeService;
    @Resource
    private IBusRoomsLivingOrderService busRoomsLivingOrderService;
    @Resource
    private IBusRoomBookingOrdersService busRoomBookingOrdersService;

    @Resource
    private IFwRoomRepairService fwRoomRepairService;

    @Resource
    private IFwRoomLockService fwRoomLockService;

    @Resource
    private IFwRoomCleanService fwRoomCleanService;

    @ApiOperation(value="房间分页列表查询", notes="房间分页列表查询")
    @GetMapping(value = "/list")
    public Result list(CesRoomSearchDto dto){
        if(dto.getPageNo().intValue() <= 0){
            return Result.error("页数不能小于等于0");
        }
        if(dto.getPageSize().intValue() < 10){
            return Result.error("分页条数不能小于10");
        }
        try{
            return  roomsService.list(dto);
        }catch (Exception e){
            return Result.error(e.getMessage());
        }
    }

    @ApiOperation(value="批量修改密码", notes="批量修改密码")
    @GetMapping(value = "/batchEditPassword")
    public Result<Boolean> batchEditPassword(CesRoomSearchDto dto, String type, String firstValue, String endValue){
        return Result.ok(roomsService.batchEditPassword(dto, type, firstValue, endValue));
    }

    @ApiOperation(value="实时房态-房间列表", notes="实时房态")
    @GetMapping(value = "/realtime-rooms")
    public Result<List<FloorWithBuildingVo>> getHotelRooms(@RequestParam Map params){
        Object hotelId = params.get("hotelId");
        if(null != hotelId) {
            List<FloorWithBuildingVo> floors = buildingFloorService.getHotelFloors(hotelId.toString());
            List<String> ids = floors.stream().map(s->s.getId()).collect(Collectors.toList());
            List<CesRoomLayout> layouts = layoutService.list(Wrappers.<CesRoomLayout>query().eq("hotel_id",hotelId.toString()).eq("invalid", false));
            // todo: 待更改。
            List<CesRooms> allRooms = !ids.isEmpty() ?  roomsService.list(Wrappers.<CesRooms>query().eq("invalid",false).in("floor_id",ids)): null;
            if(allRooms == null || allRooms.isEmpty()) {
                return Result.ok(new ArrayList());
            }
            List<FloorBuildingRoomVo> otherInfos = bookingOrdersService.getRealtimeInfo(allRooms);
            List<FwRoomLock> unLockeds = fwRoomLockService.list(Wrappers.<FwRoomLock>query().eq("hotel_id",hotelId));
            List<FwRoomRepair> unRepairs = fwRoomRepairService.list(Wrappers.<FwRoomRepair>query().eq("hotel_id",hotelId).eq("status",1));

            floors.forEach(s-> {
                List<CesRooms> floorRooms = allRooms.stream().filter(a->a.getFloorId().equals(s.getId())).collect(Collectors.toList());
                List<FloorBuildingRoomVo> roomInfos = new ArrayList<>();
                floorRooms.forEach(a -> {
                    FloorBuildingRoomVo roomVo = new FloorBuildingRoomVo();
                    //房型
                    Optional<CesRoomLayout> opLayout = layouts.stream().filter(c-> c.getId().equals(a.getLayoutId())).findFirst();
                    if(!opLayout.isPresent()) return; // 没有房型的房间给他去掉
                    roomVo.setLayout(opLayout.get());
                    //房间
                    roomVo.setRoomInfo(a);
                    // 订单
                    Optional<FloorBuildingRoomVo> opFindRoomVo = otherInfos.stream().filter(p->p.getRoomId().equals(a.getId())).findFirst();
                    if(opFindRoomVo.isPresent()) {
                        roomVo.setLivingData(opFindRoomVo.get().getLivingData());
                        roomVo.setBookingData(opFindRoomVo.get().getBookingData());
                    }
                    // 维修房
                    if(a.getRoomStatus().equals(RoomStatusEnum.IN_SERVICE.getKey())){
                        Optional<FwRoomRepair> optionalFwRoomRepair = unRepairs.stream().filter(u->u.getRoomId().equals(a.getId())).findFirst();
                        if(!optionalFwRoomRepair.isPresent()){
                            FwRoomRepair tempRepairInfo = new FwRoomRepair();
                            tempRepairInfo.setRemark("暂无");
                            roomVo.setRepairInfo(tempRepairInfo);
                        } else {
                            roomVo.setRepairInfo(optionalFwRoomRepair.get());
                        }
                    }
                    // 锁房信息
                    if(a.getRoomStatus().equals(RoomStatusEnum.ON_LOCK.getKey())){
                        Optional<FwRoomLock> optionalFwRoomLock = unLockeds.stream().filter(u->u.getRoomId().equals(a.getId())).findFirst();
                        if(!optionalFwRoomLock.isPresent()){
                            FwRoomLock tempLockInfo = new FwRoomLock();
                            tempLockInfo.setRemark("暂无");
                            roomVo.setLockInfo(tempLockInfo);
                        } else {
                            roomVo.setLockInfo(optionalFwRoomLock.get());
                        }
                    }
                    roomInfos.add(roomVo);
                });
                s.setRooms(roomInfos);
            });
            return Result.ok(floors);
        }

        throw new JeecgBootException("参数-酒店id必传");
    }



    /**
     * 可用房间
     * @param param
     * @return
     */
    @ApiOperation(value="可用房间", notes="可用房间")
    @GetMapping(value = "/can-user-rooms")
    public Result<List<CanUseResultVo>> getCanUseRooms(CanUseRequestParamDto param) {
        if(param.getHotelId()==null || param.getHotelId().isEmpty())
            throw new JeecgBootException("参数错误");
        if(param.getEndOf() == null || param.getStartOf() == null)
            throw new JeecgBootException("请传入时间范围");
        return Result.ok(roomsService.getCanUseRooms(param));
    }

    /**
     * 房间状态-带点颜色
     * @param hotelId
     * @return
     */
    @ApiOperation(value="房间状态-带点颜色", notes="房间状态-带点颜色")
    @GetMapping(value = "/room-status-color")
    public Result<List<DictModel>> getCanUseRooms(@RequestParam String hotelId) {
        List<DictModel> dictModels = RoomStatusEnum.getDictList();
        dictModels.forEach(s->{
            String colorStr="";
            switch (s.getValue()) {
                case "1":
                    colorStr = "#08F0CC";
                    break;
                case "2":
                    colorStr = "#0A0A0A";
                    break;
                case "3":
                    colorStr = "#CC3307";
                    break;
                case "4":
                    colorStr = "#801234";
                    break;
                case "5":
                    colorStr = "#71935b";
                    break;
                case "6":
                    colorStr = "#CDCDCD";
                    break;
                case "7":
                    colorStr = "#DE9751FF";
                    break;
                default: colorStr = "#CCCCCC";

            }
            s.setExtend(colorStr);
        });
        return Result.OK("",dictModels);
    }

    /**
     * 根据id查询房间
     */
    @AutoLog(value = "根据id查询房间")
    @ApiOperation(value="根据id查询房间", notes="save")
    @GetMapping(value = "/getRoomById")
    public Result<CesRooms> getRoomById(String roomId){
        CesRooms room = roomsService.getOne(Wrappers.<CesRooms>lambdaQuery().eq(CesRooms::getId, roomId).eq(CesRooms::getInvalid, false));
        if (room == null){
            return Result.error("未找到房间");
        }
        return Result.ok(room);
    }

    /**
     * 保存房间
     * @param dto
     * @return
     */
    @AutoLog(value = "保存房间")
    @ApiOperation(value="save房间", notes="save")
    @PostMapping(value = "/save")
    public Result save(@RequestBody CesRoomsDto dto){
        if(StringUtils.isBlank(dto.getHotelId())){
            return Result.error(ResultCode.PARAM_MISS);
        }
        if(StringUtils.isBlank(dto.getBuildId())){
            return Result.error(ResultCode.PARAM_MISS);
        }
        if(StringUtils.isBlank(dto.getFloorId())){
            return Result.error(ResultCode.PARAM_MISS);
        }
        if(StringUtils.isBlank(dto.getName())){
            return Result.error(ResultCode.PARAM_MISS);
        }
        try{
            return  roomsService.create(dto);
        }catch (Exception e){
            return Result.error(e.getMessage());
        }
    }

    @AutoLog(value = "修改房间")
    @ApiOperation(value="修改房间", notes="修改房间")
    @PutMapping(value = "/modify")
    public Result modify(@RequestBody CesRoomsDto dto){
        if(StringUtils.isBlank(dto.getId())){
            return Result.error(ResultCode.PARAM_MISS,"数据ID必传!");
        }
        try{
            return  roomsService.modify(dto);
        }catch (Exception e){
            return Result.error(e.getMessage());
        }
    }

    @AutoLog(value = "删除单个房间")
    @ApiOperation(value="删除单个房间", notes="删除单个房间")
    @DeleteMapping(value = "/deleteOne")
    public Result delete(@RequestParam String  id){
        if(StringUtils.isBlank(id)){
            return Result.error(ResultCode.PARAM_MISS,"数据ID必传!");
        }
        try{
            return  roomsService.deleteOne(id);
        }catch (Exception e){
            return Result.error(e.getMessage());
        }
    }

    @AutoLog(value = "批量删除房间")
    @ApiOperation(value="批量删除房间", notes="批量删除房间")
    @DeleteMapping(value = "/delete")
    public Result delete(@RequestBody CesRoomDelDto dto){
        if(StringUtils.isBlank(dto.getIdStr())){
            return Result.error(ResultCode.PARAM_MISS,"数据IDS必传!");
        }
        try{
            List<String> ids = Arrays.stream(dto.getIdStr().split(",")).collect(Collectors.toList());
            return  roomsService.delete(ids);
        }catch (Exception e){
            return Result.error(e.getMessage());
        }
    }

    @AutoLog(value = "删除所有房间")
    @ApiOperation(value="删除所有房间", notes="删除所有房间")
    @DeleteMapping(value = "/removeAll")
    public Result removeAll(@RequestBody CesRoomDelDto dto){
        if(StringUtils.isBlank(dto.getHotelId())){
            return Result.error(ResultCode.PARAM_MISS,"酒店ID必传!");
        }
        try{
            return  roomsService.removeAll(dto.getHotelId());
        }catch (Exception e){
            return Result.error(e.getMessage());
        }
    }

    @AutoLog(value = "批量添加房间")
    @ApiOperation(value="批量添加房间", notes="批量添加房间")
    @PostMapping(value = "/saveBatchRoom")
    public Result saveBatchRoom(@RequestBody BatchRoomsDto dto){
        if(StringUtils.isBlank(dto.getHotelId())){
            return Result.error(ResultCode.PARAM_MISS,"酒店ID必传!");
        }
        if(StringUtils.isBlank(dto.getBuildId())){
            return Result.error(ResultCode.PARAM_MISS,"楼栋ID必传!");
        }

        List<BatchBuildFloorRoomDto> children = dto.getChildren();
        if(CollectionUtil.isEmpty(children)){
            return Result.error(ResultCode.PARAM_MISS,"楼层房间数据必传!");
        }else{
            //判断数据是否正确
            for (int i = 0; i < children.size() ; i++) {
                BatchBuildFloorRoomDto v = children.get(i);
                if(StringUtils.isBlank(v.getFloorName())) return  Result.error("楼层名称必传!");
                List<CesRooms> rooms = v.getChildren();
                if(CollectionUtil.isEmpty(rooms)) return Result.error("房间数据必传!");
                for (int j = 0; j < rooms.size(); j++) {
                    CesRooms room = rooms.get(j);
                    if(StringUtils.isBlank(room.getLayoutId())) return  Result.error("绑定房型必传!");
                    if(StringUtils.isBlank(room.getName())) return Result.error("房间名称必传!");
                 }
            }
        }
        try{
            return  roomsService.saveBatchRoom(dto);
        }catch (Exception e){
            return Result.error(e.getMessage());
        }
    }

    @ApiOperation(value="通过楼层获取房间列表", notes="通过楼层获取房间列表")
    @GetMapping(value = "/queryByFloorId")
    public Result queryByFloorId(@RequestParam String floorId){
        if(StringUtils.isBlank(floorId)){
            return Result.error(ResultCode.PARAM_MISS);
        }
        try{
            return  roomsService.queryByFloorId(floorId);
        }catch (Exception e){
            return Result.error(e.getMessage());
        }
    }

    @ApiOperation(value="通过酒店Id获取房间列表", notes="通过酒店Id获取房间列表")
    @GetMapping(value = "/queryByHotelId")
    public Result queryByHotelId(@RequestParam String hotelId){
        if(StringUtils.isBlank(hotelId)){
            return Result.error(ResultCode.PARAM_MISS);
        }
        try{
            return  roomsService.queryByHotelId(hotelId);
        }catch (Exception e){
            return Result.error(e.getMessage());
        }
    }

    /**
     * 房间智障
     * @param roomIds
     * @return
     */
    @AutoLog(value = "房间置脏")
    @ApiOperation(value="房间置脏", notes="房间置脏")
    @PostMapping(value = "/dirtyRoom")
    public Result<String> dirtyRoom(@RequestParam(name="roomIds",required=true) String roomIds) {
        List<String> list = Arrays.asList(roomIds.split(","));
        for (String s : list) {
            CesRooms cesRooms = roomsService.getById(s);
            if (ObjectUtils.isNotEmpty(cesRooms)) {
                if (cesRooms.getRoomStatus().equals(RoomStatusEnum.EMPTY_CLEAR.getKey())) {
                    cesRooms.setLastRoomStatus(RoomStatusEnum.EMPTY_DIRTY.getKey());
                    cesRooms.setRoomStatus(RoomStatusEnum.EMPTY_DIRTY.getKey());
                } else if (cesRooms.getRoomStatus().equals(RoomStatusEnum.LIVE_CLEAR.getKey())) {
                    cesRooms.setLastRoomStatus(RoomStatusEnum.LIVE_DIRTY.getKey());
                    cesRooms.setRoomStatus(RoomStatusEnum.LIVE_DIRTY.getKey());
                } else if (cesRooms.getRoomStatus().equals(RoomStatusEnum.RESERVE.getKey())){
                    cesRooms.setLastRoomStatus(RoomStatusEnum.EMPTY_DIRTY.getKey());
                }
                roomsService.updateById(cesRooms);
            }
        }
        return Result.OK("房间置脏成功!");
    }

    @AutoLog(value = "房间状态置预约")
    @ApiOperation(value="房间状态置预约", notes="房间状态置预约")
    @GetMapping(value = "/changeStateReserve")
    public Result changeStateReserve() {
        return Result.ok(roomsService.getReserveRoom());
    }

    @ApiOperation(value = "房间统计", notes = "房间统计")
    @GetMapping(value = "/roomSummary")
    public Result getRoomSummary(@RequestParam String hotelId) {
        if (StringUtils.isBlank(hotelId)) {
            return Result.error("请传入酒店id");
        }
        LambdaQueryWrapper<CesRooms> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(CesRooms::getHotelId, hotelId);
        lambdaQueryWrapper.eq(CesRooms::getInvalid, false);
        lambdaQueryWrapper.and(j -> {
            j.or().eq(CesRooms::getRoomStatus, RoomStatusEnum.LIVE_DIRTY.getKey());
            j.or().eq(CesRooms::getRoomStatus, RoomStatusEnum.LIVE_CLEAR.getKey());
        });
        Long liveCount = roomsService.count(lambdaQueryWrapper);

        lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(CesRooms::getHotelId, hotelId);
        lambdaQueryWrapper.eq(CesRooms::getInvalid, false);
        Long count = roomsService.count(lambdaQueryWrapper);
        List<Long> counts = new ArrayList<>();
        counts.add(count);//房间总数
        counts.add(liveCount);//在住总数

        DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        Calendar calendar = new GregorianCalendar();
        calendar.setTime(DateTime.now());
        calendar.add(Calendar.DATE, 1);
        String dateString = formatter.format(calendar.getTime());

        LambdaQueryWrapper<BusOrderFee> lambdaQueryWrapper2 = new LambdaQueryWrapper<>();
        lambdaQueryWrapper2.eq(BusOrderFee::getHotelId, hotelId);
        lambdaQueryWrapper2.eq(BusOrderFee::getSubjectType, FeeSubjectType.MEI_RI_FANG_FEI.getKey());
        lambdaQueryWrapper2.ge(BusOrderFee::getCreateTime, LocalDate.now());
        lambdaQueryWrapper2.le(BusOrderFee::getCreateTime, DateUtil.parseDate(dateString));
        List<BusOrderFee> busOrderFees = busOrderFeeService.list(lambdaQueryWrapper2);
        BigDecimal sum = BigDecimal.ZERO;
        for (BusOrderFee busOrderFee : busOrderFees) {
            sum = sum.add(busOrderFee.getMoney());
        }
        if(busOrderFees.size()>0) {
            Long divide = sum.divide(new BigDecimal(busOrderFees.size()), 6, RoundingMode.HALF_UP).longValue();
            counts.add(divide);//今日平均房价
        }
        else{
            counts.add(Long.valueOf(0));//今日平均房价
        }
        LambdaQueryWrapper<BusRoomsLivingOrder> lambdaQueryWrapper3 = new LambdaQueryWrapper<>();
        lambdaQueryWrapper3.ge(BusRoomsLivingOrder::getDueOutTime, DateUtil.formatDate(new Date())+" 00:00:00");
        lambdaQueryWrapper3.eq(BusRoomsLivingOrder::getHotelId, hotelId);
        lambdaQueryWrapper3.le(BusRoomsLivingOrder::getDueOutTime, DateUtil.formatDate(new Date())+" 23:59:59");
        Long ylCount = busRoomsLivingOrderService.count(lambdaQueryWrapper3);
        counts.add(ylCount);//今日预离

        LambdaQueryWrapper<BusRoomBookingOrders> lambdaQueryWrapper4 = new LambdaQueryWrapper<>();
        lambdaQueryWrapper4.ge(BusRoomBookingOrders::getArrivalTime, LocalDate.now());
        lambdaQueryWrapper4.le(BusRoomBookingOrders::getArrivalTime, DateUtil.parseDate(dateString));

        Long ydCount =Long.parseLong( busRoomBookingOrdersService.countTodayYD(hotelId).size()+"");
        counts.add(ydCount);//今日预抵

        LambdaQueryWrapper<BusRoomsLivingOrder> lambdaQueryWrapper5 = new LambdaQueryWrapper<>();
        lambdaQueryWrapper5.and(j->{
            j.or().eq(BusRoomsLivingOrder::getSettleType,-1);
            j.or().eq(BusRoomsLivingOrder::getSettleType,2);
        });
        lambdaQueryWrapper5.ge(BusRoomsLivingOrder::getDueOutTime, LocalDate.now());
        lambdaQueryWrapper5.le(BusRoomsLivingOrder::getDueOutTime, DateUtil.parseDate(dateString));
        lambdaQueryWrapper5.eq(BusRoomsLivingOrder::getHotelId, hotelId);
        Long qfCount = busRoomsLivingOrderService.count(lambdaQueryWrapper5);
        counts.add(qfCount);//今日欠费

        LambdaQueryWrapper<CesRooms> lambdaQueryWrapper6 = new LambdaQueryWrapper<>();
        lambdaQueryWrapper6.eq(CesRooms::getHotelId, hotelId);
        lambdaQueryWrapper6.eq(CesRooms::getInvalid, false);
        lambdaQueryWrapper6.and(j -> {
            j.eq(CesRooms::getRoomStatus, RoomStatusEnum.LIVE_DIRTY.getKey());
            j.or().eq(CesRooms::getRoomStatus, RoomStatusEnum.EMPTY_DIRTY.getKey());
        });
        Long zfCount = roomsService.count(lambdaQueryWrapper6);
        counts.add(zfCount);//脏房
        return Result.OK(counts);
    }

    @ApiOperation(value = "在住来源统计", notes = "在住来源统计")
    @GetMapping(value = "/livingSourceStat")
    public Result getLivingSourceStat(@RequestParam String hotelId) {
        if (StringUtils.isBlank(hotelId)) {
            return Result.error("请传入酒店id");
        }
        return Result.ok(roomsService.livingSourceStat(hotelId));
    }

    @ApiOperation(value = "房态统计", notes = "房态统计")
    @GetMapping(value = "/roomLiveStat")
    public Result getRoomLiveStat(@RequestParam String hotelId) {
        if (StringUtils.isBlank(hotelId)) {
            return Result.error("请传入酒店id");
        }
        return Result.ok(roomsService.roomLiveStat(hotelId));
    }

    @ApiOperation(value = "房间门市价", notes = "房间门市价")
    @GetMapping(value = "/get-room-mkt-price")
    public Result<BigDecimal> getRoomMktPrice(String roomId) {
        return Result.ok(roomsService.getRoomMktPrice(roomId));
    }

    @GetMapping("/needCleanRoom")
    public Result<List<CesRooms>> needCleanRoom(String hotelId){
        List<CesRooms> cesRoomsList = roomsService.list(Wrappers.<CesRooms>lambdaQuery().eq(CesRooms::getHotelId, hotelId)
                .eq(CesRooms::getInvalid, 0).and(e -> e.eq(CesRooms::getRoomStatus, 2).or().eq(CesRooms::getRoomStatus, 4)));
        List<FwRoomClean> roomCleanList = fwRoomCleanService.list(Wrappers.<FwRoomClean>lambdaQuery()
                .eq(FwRoomClean::getState, 0).eq(FwRoomClean::getHotelId, hotelId).select(FwRoomClean::getRoomId));
        Set<String> roomIds = roomCleanList.stream().map(FwRoomClean::getRoomId).collect(Collectors.toSet());
        List<CesRooms> cesRooms = cesRoomsList.stream().filter(e -> !roomIds.contains(e.getId())).collect(Collectors.toList());
        return Result.ok(cesRooms);
    }
}

